{% extends 'base.html' %}  

{% block title %}  
    {% if form.instance.id %}编辑钱包{% else %}添加钱包{% endif %} - SaveStar  
{% endblock %}  

{% block page_title %}  
    {% if form.instance.id %}编辑钱包{% else %}添加钱包{% endif %}  
{% endblock %}  

{% block content %}  
<div class="row justify-content-center">  
    <div class="col-md-8">  
        <div class="card">  
            <div class="card-header">  
                <h5 class="mb-0">{% if form.instance.id %}编辑钱包{% else %}添加钱包{% endif %}</h5>  
            </div>  
            <div class="card-body">  
                <form method="post">  
                    {% csrf_token %}  

                    <div class="mb-3">  
                        <label for="id_name" class="form-label">钱包名称</label>  
                        <input type="text" name="name" id="id_name" class="form-control" value="{{ form.instance.name }}" required>  
                        {% if form.name.errors %}  
                            <div class="text-danger">  
                                {% for error in form.name.errors %}  
                                    {{ error }}  
                                {% endfor %}  
                            </div>  
                        {% endif %}  
                    </div>  

                    <div class="mb-3">  
                        <label for="id_initial_balance" class="form-label">初始金额</label>  
                        <div class="input-group">  
                            <span class="input-group-text">¥</span>  
                            <input type="number" name="initial_balance" id="id_initial_balance" class="form-control"   
                                   value="{{ form.instance.initial_balance|default:0 }}" step="0.01" required>  
                        </div>  
                        {% if form.initial_balance.errors %}  
                            <div class="text-danger">  
                                {% for error in form.initial_balance.errors %}  
                                    {{ error }}  
                                {% endfor %}  
                            </div>  
                        {% endif %}  
                    </div>  

                    <div class="mb-3">  
                        <label for="id_icon" class="form-label">图标</label>  
                        <select name="icon" id="id_icon" class="form-select">  
                            <option value="wallet" {% if form.instance.icon == 'wallet' %}selected{% endif %}>钱包</option>  
                            <option value="credit-card" {% if form.instance.icon == 'credit-card' %}selected{% endif %}>信用卡</option>  
                            <option value="piggy-bank" {% if form.instance.icon == 'piggy-bank' %}selected{% endif %}>储蓄罐</option>  
                            <option value="landmark" {% if form.instance.icon == 'landmark' %}selected{% endif %}>银行</option>  
                            <option value="money-bill-wave" {% if form.instance.icon == 'money-bill-wave' %}selected{% endif %}>现金</option>  
                            <option value="coins" {% if form.instance.icon == 'coins' %}selected{% endif %}>硬币</option>  
                        </select>  
                    </div>  

                    <div class="mb-3">  
                        <label for="id_warning_balance" class="form-label">预警余额</label>  
                        <div class="input-group">  
                            <span class="input-group-text">¥</span>  
                            <input type="number" name="warning_balance" id="id_warning_balance" class="form-control"   
                                   value="{{ form.instance.warning_balance|default:0 }}" step="0.01">  
                        </div>  
                        <div class="form-text">当余额低于此数值时将发出预警提醒</div>  
                    </div>  

                    <div class="mb-3 form-check">  
                        <input type="checkbox" name="is_active" id="id_is_active" class="form-check-input"   
                               {% if form.instance.id %}{% if form.instance.is_active %}checked{% endif %}{% else %}checked{% endif %}>  
                        <label for="id_is_active" class="form-check-label">钱包激活</label>  
                    </div>  

                    <div class="d-flex justify-content-between">  
                        <a href="{% url 'wallet_list' %}" class="btn btn-outline-secondary">返回</a>  
                        <button type="submit" class="btn btn-primary">保存</button>  
                    </div>  
                </form>  
            </div>  
        </div>  
    </div>  
</div>  
{% endblock %}